package com.pan.alg.leecode;

/**
 * @author by panstark
 * @description
 * @notice
 * @date 2021/7/12
 */
public class LeeCode26 {

    public int removeDuplicates(int[] nums) {
        //用来记录删除后的坐标
        int index =0;
        //第一个数肯定在新数组里，为了防止数组越界，从i=1开始
        for (int i = 1; i < nums.length; i++) {
            if(nums[i-1]!=nums[i]){
                index++;
                nums[index]=nums[i];
            }
        }

        return index+1;
    }

    public static void main(String[] args) {
        LeeCode26 l = new LeeCode26();
        int[] nums = new int[]{1,1,2,2,3};
        int index =l.removeDuplicates(nums);
        System.out.println("index:"+index);
        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }
    }
}
